<template>
  <div class="purchaseForm">
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true">
        <el-form-item>
          <el-button type="primary" @click="submitForm">已购买提交</el-button>
        </el-form-item>
      </el-form>
    </el-col>
    <el-col :span="24" class="toolbar">
      <div class="apply-data">
        <!-- <div class="ad-item">
          <div class="tit">部门:</div>
          <div class="text">{{dataDetail.deptname}}</div>
        </div>
        <div class="ad-item">
          <div class="tit">日期:</div>
          <div class="text">{{formatTime(dataDetail.createtime)}}</div>
        </div> -->
        <div class="ad-item">
          <div class="tit">单据编号:</div>
          <div class="text">{{dataDetail.orderNum}}</div>
        </div>
        <div class="ad-item">
          <div class="tit">申请日期:</div>
          <div class="text">{{formatTime(dataDetail.uploadDay)}}</div>
        </div>
        <div class="ad-item">
          <div class="tit">公司部门:</div>
          <div class="text">{{dataDetail.unitname}}</div>
        </div>
        <div class="ad-item">
          <div class="tit">请购人:</div>
          <div class="text">{{dataDetail.psnname}}</div>
        </div>
        <div class="ad-item">
          <div class="tit">需求日期:</div>
          <div class="text">{{dataDetail.needDay}}</div>
        </div>
        <div class="ad-item">
          <div class="tit">已购买提交日期:</div>
          <div class="text">{{formatTime(dataDetail.submitTime)}}</div>
        </div>
      </div>
    </el-col>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="序号" type="index"></el-table-column>
      <el-table-column prop="productName" label="产品名称"></el-table-column>
      <el-table-column prop="invspec" label="规格型号"></el-table-column>
      <el-table-column prop="inquiryCustname" label="供应商"></el-table-column>
      <!-- <el-table-column prop label="库存保质期"></el-table-column> -->
      <!-- <el-table-column label="请购单数据" align="center" :label-class-name="'labelFont'"> -->
        <el-table-column prop="file" label="附件" width="140" align="center">
          <template slot-scope="scope">
            <div>
              <el-button @click="showImg(scope.row.inquiryProductUrl)" size="small" type="primary">查看</el-button>
            </div>
          </template>
        </el-table-column>
        <!-- <el-table-column label="询价单供应商" prop="supplierName"></el-table-column> -->
        <el-table-column label="单价(元)" align="center" prop="inquiryUnitPrice"></el-table-column>
        <el-table-column prop="measurement" label="单位"></el-table-column>
        <el-table-column label="本期申请数量" align="center" prop="requisitionsHowMany"></el-table-column>
        <el-table-column label="税率(元)" align="center" prop="requisitionsTaxRate"></el-table-column>
        <el-table-column label="总价" align="center" prop="inquiryAllMoneys"></el-table-column>
        <el-table-column label="是否含运费" align="center">
          <template slot-scope="scope">
            <div>{{scope.row.requisitionsIsFreight == 'Y'?"是":"否"}}</div>
          </template>
        </el-table-column>
        <el-table-column label="付款方式" align="center" prop="inquiryPayType"></el-table-column>
        <el-table-column label="地址及联系方式" align="center" prop="inquiryAddressPhone"></el-table-column>
        <el-table-column label="用途" align="center" prop="requisitionsHowUse"></el-table-column>
        <el-table-column label="备注" align="center" prop="inquiryRemark"></el-table-column>
      <!-- </el-table-column> -->
    </el-table>
    <el-col :span="24" class="toolbar">
      <div class="sign-remarks">
        <div class="tit">备注:{{dataDetail.remark}}</div>
      </div>
    </el-col>
    <el-col :span="24" class="toolbar">
      <div class="sign-data">
        <div class="sd-item">制单人:{{dataDetail.singlePerson}}</div>
        <div class="sd-item">审核人:{{dataDetail.auditor}}</div>
        <div class="sd-item">审核时间:{{formatTime(dataDetail.auditTime)}}</div>
        <div class="sd-item">变更人:{{dataDetail.modifiername}}</div>
        <div class="sd-item">变更日期:{{formatTime(dataDetail.modifytime)}}</div>
      </div>
    </el-col>
    <!-- 展示图片 -->
    <el-dialog title="附件" :visible.sync="dialogImgShow">
      <div class="showImgDiv">
        <img :src="showImgUrl" alt />
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { WlcPurchaseDetail, WlcPurchaseSubmit } from "../../api/api";
import moment from "moment";
export default {
  data() {
    return {
      tableData: [],
      page: {
        page: 1,
        pageSize: 10,
      },
      showImgUrl: "",
      dialogImgShow: false, //是否展示图片
      productList: [], //新增 询价单列表
      dataDetail: {}, //请购单详情

      // 部门申请的数据列表
      deparArr: [],
      //新增完后选择的请购单
      InquiryList: [],
      tableIndex: null, //点击第几个table
      selectInquiryArr: [], //选中的请购单
      inquiryData: {},
      totalData: {
        num: 0,
        price: 0,
      },
      tableAllID: "", //点击选择询价单  allId
    };
  },
  methods: {
    //点击提交
    submitForm() {
      this.$confirm("是否提交?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let id = this.$route.query.id;
        WlcPurchaseSubmit({ id }).then((res) => {
          this.$message({
            message: "成功",
            type: "success",
          });
        });
      });
    },
    //选择完询价单  点击确定
    clickInquire() {
      let isSelect = false;
      let obj = {};
      this.InquiryList.map((item) => {
        if (item.checked == 1) {
          isSelect = true;
          obj = item;
        }
      });
      if (isSelect) {
        this.finishSelect(obj);
      } else {
        this.$message({
          message: "请选择询价单",
          type: "warning",
        });
      }
    },
    //展示图片
    showImg(url) {
      console.log(url)
      if (url) {
        this.showImgUrl = url;
        this.dialogImgShow = true;
      } else {
        this.$message({
          message: "暂无图片",
          type: "warning",
        });
      }
    },
    //格式化时间
    formatTime(time) {
      if (time) {
        return moment(time).format("YYYY-MM-DD");
      } else {
        return "";
      }
    },
    //获取请购单详情
    getDetail(id) {
      WlcPurchaseDetail({ id }).then((res) => {
        this.dataDetail = res;
        this.tableData = res.wlcBankPurchasingOrders;
      });
    },
  },
  created() {
    if (this.$route.query.id) {
      this.getDetail(this.$route.query.id);
    }
  },
};
</script>

<style lang="less" scoped>
.total-data {
  display: flex;
  justify-content: center;
  .total-item {
    font-weight: bold;
    font-size: 16px;
    color: #666;
    width: 20%;
  }
}
.apply-data {
  display: flex;
  flex-wrap: wrap;
  .ad-item {
    display: flex;
    height: 30px;
    line-height: 30px;
    margin-right: 70px;
    color: #666;
    font-size: 14px;
  }
}
.sign-remarks {
  width: 100%;
  border-bottom: 1px solid #999;
  font-size: 14px;
  height: 40px;
  line-height: 40px;
  color: #333;
}
.sign-data {
  display: flex;
  .sd-item {
    flex: 1;
    color: #333;
  }
}
.inquiryTit {
  font-weight: bold;
  font-size: 16px;
  margin-bottom: 10px;
}
.inquiry-list {
  img {
    max-width: 75px;
    max-height: 75px;
  }
}
.el-icon-circle-check {
  font-size: 20px;
  color: #409eff;
}
.inquire-table {
  margin-top: 20px;
  .it-tit {
    color: #666;
    font-weight: bold;
    margin-bottom: 10px;
  }
}
.showImgDiv {
  width: 100%;
  img {
    width: 100%;
  }
}
</style>
<style lang="less">
.el-table th > .cell.labelFont {
  font-weight: bold;
  color: #333 !important;
}
</style>
